/**
 * @Title: BusinessUtil.java
 * @author 6335yz
 * @date 2015年8月18日 下午1:23:58
 */
package com.shanghaionstar.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.View;

import com.google.gson.Gson;
import com.onstar.cn.auth.AuthTokenRequestEntity;
import com.onstar.cn.auth.userProfile.ServiceEntitlement;
import com.onstar.cn.auth.userProfile.Subscriber;
import com.onstar.cn.auth.userProfile.Vehicle;
import com.onstar.cn.auth.userProfile.VehicleUnitFeature;
import com.onstar.cn.common.IServerUrls;
import com.onstar.cn.common.exception.HttpException;
import com.onstar.cn.common.exception.OnStarException;
import com.onstar.cn.common.log.LogManager;
import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.common.util.DeviceUtil;
import com.onstar.cn.common.util.EncryptUtil;
import com.onstar.cn.common.util.PreferencesUtls;
import com.onstar.cn.framework.mvp.base.IMVPView;
import com.onstar.cn.framework.mvp.base.core.BaseFragmentActivity;
import com.onstar.cn.framework.network.http.CommonError;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.enumtype.PackageType;
import com.onstar.cn.mag.enumtype.RemoteCommandsType;
import com.onstar.cn.mag.publicService.SessionEntity;
import com.onstar.cn.sqlite.entities.ConfigParams;
import com.onstar.cn.sqlite.entities.PollingEntity;
import com.onstar.cn.vehicle.entity.ErrorEnum;
import com.onstar.cn.vehicle.entity.ErrorInfo;
import com.onstar.cn.weight.ToastView;
import com.shanghaionstar.OnstarApplication;
import com.shanghaionstar.R;
import com.shanghaionstar.alarm.AlarmActionType;
import com.shanghaionstar.alarm.AlarmProxy;
import com.shanghaionstar.enumtype.FunctionNameFindId;
import com.shanghaionstar.enumtype.OperateType;
import com.shanghaionstar.joinme.JoinMeUtil;
import com.shanghaionstar.login.register.JoinMeUtils;
import com.shanghaionstar.notification.service.NotificationControl;
import com.shanghaionstar.pin.PinUtil;
import com.shanghaionstar.report.bean.DynamicDTO;
import com.shanghaionstar.report.bean.ReportReqParam;
import com.shanghaionstar.report.model.ReportModel;
import com.shanghaionstar.report.pool.PoolThread;
import com.shanghaionstar.report.pool.PoolThreadExecutor;
import com.shanghaionstar.service.VehicleManager;
import com.shanghaionstar.service.VehiclePollingService;
import com.shanghaionstar.servicepackage.OnstarBuyPackageActivity;
import com.shanghaionstar.sqlite.ConfigParamsServiceImpl;

import org.apache.http.conn.ConnectTimeoutException;
import org.json.JSONException;

import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.functions.Action1;

/**
 * @author 6335yz
 * @ClassName: BusinessUtil
 * @Description: TODO
 * @date 2015年8月18日 下午1:23:58
 */
@SuppressWarnings("deprecation")
public class BusinessUtil {


    public static String getConfigValue(String key, Context context) {
        String value = "";
//        if ((Constants.SERVER_URL.equals(key) || FinalConfigParams.AUTHSERVERURL.equals(key)) &&
//                DevelopServerEnvironmentUtil.getInstance().isDevelopMode(context)) {
//            String devUrl;
//            if (Constants.SERVER_URL.equals(key)) {
//                devUrl = DevelopServerEnvironmentUtil.getInstance().getServerUrl(context);
//                if(!CommonUtil.isNull(devUrl) && devUrl.startsWith("https")){
//                    return devUrl;
//                }
//                if (!CommonUtil.isNull(devUrl)) {
//                    return EncryptUtil.decryptBase64(context, devUrl);
//                    //     return "https://api-veh-idt4.shanghaionstar.com:14443";
//                }
//            } else if (FinalConfigParams.AUTHSERVERURL.equals(key)) {
//                devUrl = DevelopServerEnvironmentUtil.getInstance().getAuthServerUrl(context);
//                if(!CommonUtil.isNull(devUrl) && devUrl.startsWith("https")){
//                    return devUrl;
//                }
//                if (!CommonUtil.isNull(devUrl)) {
//                    return EncryptUtil.decryptBase64(context, devUrl);
//                }
//            }
//        } else if ((Constants.SERVER_URL.equals(key) || FinalConfigParams.AUTHSERVERURL.equals(key))) {//如果是URL直接,不从数据库里读
//            value = EncryptUtil.decryptBase64(context, Constants.SERVER_URL_VALUE);
//            return value;
//        }
        String url = IServerUrls.mMap.get(key);
        if (!TextUtils.isEmpty(url)) {
            return EncryptUtil.decryptBase64(context, url);
        }
        ConfigParamsServiceImpl paramsServiceImpl = new ConfigParamsServiceImpl(context.getApplicationContext());
        ConfigParams configParams = paramsServiceImpl.getConfigParamByKey(key);
        if (configParams != null) {
            value = configParams.getParamValue();
        }
//        if (Constants.SERVER_URL.equals(key) || FinalConfigParams.AUTHSERVERURL.equals(key)) {
//            value = EncryptUtil.decryptBase64(context, value);
//            LogManager.getInstance(context).d("connect url:" + value);
//        }
        return value;
    }


    public static void updateConfigValue(String key, String value, Context context) {
        ConfigParamsServiceImpl paramsServiceImpl = new ConfigParamsServiceImpl(context);
        ConfigParams configParam = paramsServiceImpl.getConfigParamByKey(key);
        if (configParam != null) {
            configParam.setParamValue(value);
            paramsServiceImpl.update(configParam);
        } else {
            configParam = new ConfigParams();
            configParam.setFlag("0");
            configParam.setParamDesc("");
            configParam.setParamKey(key);
            configParam.setParamValue(value);
            paramsServiceImpl.insert(configParam);
        }
    }

    //
    public static boolean isServiceFeature(String featrue, Context context) {
        List<VehicleUnitFeature> vehicleUnitFeatures = ApplicationUtil.getInstance().getVehicleUnitFeatures();
        if (vehicleUnitFeatures == null || vehicleUnitFeatures.size() == 0) {
            return false;
        } else {
            for (VehicleUnitFeature vehicleUnitFeature : vehicleUnitFeatures) {
                if (vehicleUnitFeature.getFeatureName().equals(featrue)) {
                    return true;
                }
            }
        }
        return false;
    }

    //
    public static void loadConfig(Context context) {
        ConfigParamsServiceImpl paramsServiceImpl = new ConfigParamsServiceImpl(context);
        paramsServiceImpl.deleteALl();
        paramsServiceImpl.load();
    }

    //
//    /**
//     * 地图缓存用，进入app 调用
//     *
//     * @param context
//     */
//    public static void clearMapLoactionCache(Context context) {
//        PreferencesUtls.getInstance(context).putString(FinalConstants.SharedPreferencesConfig.USER_CURRENT_CITY_INFO, "");
//        PreferencesUtls.getInstance(context).putString(FinalConstants.SharedPreferencesConfig.USER_CURRENT_LOCATION_LATITUDE, "");
//        PreferencesUtls.getInstance(context).putString(FinalConstants.SharedPreferencesConfig.USER_CURRENT_LOCATION_LONGITUDE, "");
//    }
//
    public static ErrorInfo getErrorInfoByException(Context context, Exception e) {

        ErrorInfo errorInfo = new ErrorInfo();

        if (e instanceof UnknownHostException) {// 网络问题
            errorInfo.setCode(ErrorEnum.SOMP_901.getStringValue());
            errorInfo.setMsg(context.getString(R.string.networkError));
        } else if (e instanceof ConnectTimeoutException || e instanceof SocketTimeoutException) {// 超时
            errorInfo.setCode(ErrorEnum.SOMP_902.getStringValue());
            errorInfo.setMsg(context.getString(R.string.networkError));
        } else if (e instanceof JSONException) { // 返回的json与xsd不符合
            errorInfo.setCode(ErrorEnum.SOMP_903.getStringValue());
            errorInfo.setMsg(context.getString(R.string.networkError));
        } else {
            errorInfo.setCode(ErrorEnum.SOMP_904.getStringValue());
            errorInfo.setMsg(context.getString(R.string.networkError));
        }

        return errorInfo;
    }

    public static void showOverdueUserDialog(final Context context) {
        AlertDialogUtil.showNotCancelAlertDialog(context, R.string.dialog_warning, R.string.over_due_user,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                        Intent paymeIntent = new Intent(context, PayMeOrderActivity.class);
//                        Bundle bundle = new Bundle();
//                        bundle.putSerializable("packageType", PackageType.CORE);
//                        paymeIntent.putExtras(bundle);
//                        context.startActivity(paymeIntent);
                    }
                });
    }

    /**
     * 是否登录自动刷新
     *
     * @param context
     */
    public static void autoRefresh(Context context) {
//        String loginRole = ApplicationUtil.getInstance().getLoginRole();
//        if (loginRole != null && !loginRole.equalsIgnoreCase(JoinMeConstants.VISITOR)) {
//            if (PlaySoundUtil.getOvdAutoRefresh(context)) {
//                // 是否自动刷新
//                VehicleData dataUtil = new VehicleData(context, ApplicationUtil.getInstance().getVin(),
//                        ApplicationUtil.getInstance().getToken());
//                dataUtil.loadDatas();
//                return;
//            }
////			DatabaseOvdHistory ovdHistory = new DatabaseOvdHistory(context);
////			// 本地文件不存在，则自动刷新车况
////			boolean isExist = ovdHistory.checkDataIfExits(ApplicationUtil.getInstance().getVin();
////			if (!isExist) {
////				VehicleData dataUtil = new VehicleData(context, ApplicationUtil.getInstance().getVin(),
////						ApplicationUtil.getInstance().getToken());
////				dataUtil.loadDatas();
////			}
//        }
    }

    //
//    /**
//     * @Title: refreshPolling @Description: 当程序退出时需要重置车辆操作为failure @param @param
//     * context 设定文件 @return void 返回类型 @throws
//     */
    public static void refreshPolling(final Context context) {
        Intent intent = new Intent(context, VehiclePollingService.class);
        context.stopService(intent);
        if (!CommonUtil.isNull(ApplicationUtil.getInstance().getCurrentVehicle())) {
            VehicleManager manager = new VehicleManager(context);
            manager.refreshPollingStatus(ApplicationUtil.getInstance().getCurrentVehicle().getVin());
        }
    }

    //
//    /**
//     * @Title: checkInProgressCommand @Description:检查是否正在做车辆操作，如果有则弹出对话框 @param @param
//     * context @param @return 设定文件 @return boolean 返回类型 @throws
//     */
    public static boolean checkInProgressCommand(Context context, RemoteCommandsType remoteCommandsType) {
        return checkInProgressCommand(context, remoteCommandsType, true);
    }

    public static boolean checkInProgressCommand(Context context, RemoteCommandsType remoteCommandsType,
                                                 boolean showDialog) {
        if (!CommonUtil.isNull(ApplicationUtil.getInstance().getCurrentVehicle())) {
            String vin = ApplicationUtil.getInstance().getCurrentVehicle().getVin();
            VehicleManager manager = new VehicleManager(context);
            if (manager.isInProgressCommand(vin, remoteCommandsType)) {
               if (showDialog) {
                    AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                            context.getString(R.string.service_inProcess_alert));
                }
                return true;
            }
        }
        return false;
    }

    /**
     * @Title: sendReportByClickType @Description:
     * 发送report方法，合并B2C和MAG后台的report发送 @param @param context @param @param
     * functionNameFindId 设定文件 @return void 返回类型 @throws
     */
    private static void sendReportByClickType(final Context context, final String functionNameFindId, final String content) {
        OnstarApplication application = OnstarApplication.getApplication();
        //isLoginedSuccess:标志位 true:登录后并且成功了直接发送到服务端  false:非登录后调用后登录后失败调用
        boolean isLoginedSuccess = false;
        if (functionNameFindId.equals(FunctionNameFindId.loginregister_Login.getStringValue())) {
            isLoginedSuccess = ApplicationUtil.getInstance().isLogin();
        }
        final boolean isLogin = isLoginedSuccess;
        OperateReportUtil.operateEventReport(functionNameFindId, OperateType.CLICK, context.getApplicationContext(), isLogin, content);

    }

    /**
     * @Title: sendReportByClickType @Description:
     * 发送report方法，合并B2C和MAG后台的report发送 @param @param context @param @param
     * functionNameFindId 设定文件 @return void 返回类型 @throws
     */

    public static void sendReportByClickType(final Context mContext, final String functionNameFindId) {
        final Context context = mContext.getApplicationContext();
        PoolThread poolThread = PoolThreadExecutor.getThreadPollExecutor().getExecutorService();
        if (!poolThread.isOn()) {
            poolThread.start();
        }
        poolThread.execute(new Runnable() {
            @Override
            public void run() {
                ReportModel reportModel = new ReportModel();
                ReportReqParam reportReqParam = new ReportReqParam.ReportReqParamBuilder().channelId("0")
                        .deviceType("0")
                        .functionNameFindId(functionNameFindId)
                        .objectID("")
                        .objectType("9")
                        .operationType("")
                        .result("0")
                        .type("0").createReportReqParam();
                if (functionNameFindId.equals(FunctionNameFindId.loginregister_Login.getStringValue())) {
                    reportReqParam.result = "0";
                }
                DynamicDTO dynamicDTO = reportModel.getDynamicDTO(context, reportReqParam);
                sendReportByClickType(context.getApplicationContext(), functionNameFindId, new Gson().toJson(dynamicDTO));
            }
        });
    }

    public static void sendReportByRequestParams(final Context context, final String functionNameFindId, final ReportReqParam reportReqParam) {
        PoolThread poolThread = PoolThreadExecutor.getThreadPollExecutor().getExecutorService();
        if (!poolThread.isOn()) {
            poolThread.start();
        }
        poolThread.execute(new Runnable() {
            @Override
            public void run() {
                ReportModel reportModel = new ReportModel();
                DynamicDTO dynamicDTO = reportModel.getDynamicDTO(context, reportReqParam);
                sendReportByClickType(context.getApplicationContext(), functionNameFindId, new Gson().toJson(dynamicDTO));
            }
        });
    }

    /**
     * 用于根据URL收集report
     *
     * @param dto
     */
    public static void sendReport(final DynamicDTO dto) {
        PoolThread poolThread = PoolThreadExecutor.getThreadPollExecutor().getExecutorService();
        if (!poolThread.isOn()) {
            poolThread.start();
        }
        poolThread.execute(new Runnable() {
            @Override
            public void run() {
                sendReportByClickType(OnstarApplication.getApplication().getApplicationContext(), "", new Gson().toJson(dto));//JsonUtils.toJson(dynamicDTO)
            }
        });
    }

//	public static FinalConfigParams.ShortCutRequestType getSwitchCommand(Activity activity, int tabId) {
//		FinalConfigParams.ShortCutRequestType commandType = null;
//		MainTabActivity mainTabActivity = (MainTabActivity) (activity.getParent());
//		Bundle bundle = mainTabActivity.getSwitchParams();
//		int iCommandType = bundle.getInt(tabId + "");
//		switch (iCommandType) {
//		case R.id.lockdoor_id:
//			commandType = FinalConfigParams.ShortCutRequestType.LOCK_DOOR;
//			break;
//		case R.id.vehicleLocation_button_id:
//			commandType = FinalConfigParams.ShortCutRequestType.VEHICLE_LOCATION;
//			break;
//		case R.id.sendInfoToCarBtn:
//			commandType = FinalConfigParams.ShortCutRequestType.TBT;
//			break;
//		case R.id.sendToODDBtn:
//			commandType = FinalConfigParams.ShortCutRequestType.ODD;
//			break;
//		case R.id.assistant_report_id:
//			commandType = FinalConfigParams.ShortCutRequestType.OVD_REPORT;
//			break;
//		case R.id.option_pay_me_btn_id:
//			commandType = FinalConfigParams.ShortCutRequestType.MY_PACKAGE;
//			break;
//		case R.id.btn_start_clear:
//			commandType = FinalConfigParams.ShortCutRequestType.MAP_ROUTE_FAVORITE_START;
//			break;
//		case R.id.btn_end_clear:
//			commandType = FinalConfigParams.ShortCutRequestType.MAP_ROUTE_FAVORITE_END;
//			break;
//		case R.id.button_poi_favourite:
//			commandType = FinalConfigParams.ShortCutRequestType.MAP_FAVORITE;
//			break;
//		case R.id.wifi_layout:
//			commandType = FinalConfigParams.ShortCutRequestType.WIFI_GET;
//			break;
//		case R.id.assistant_story_id:
//			commandType = FinalConfigParams.ShortCutRequestType.MORE_TRUE_STORY;
//			break;
//		case R.id.btn_favorite:
//			commandType = FinalConfigParams.ShortCutRequestType.MAP_FAVORITE;
//			break;
//		case R.id.option_fwjs_id:
//			commandType = FinalConfigParams.ShortCutRequestType.MORE_FWJS;
//			break;
//		case R.id.upgrade_to_owner_btn_id:
//			commandType = FinalConfigParams.ShortCutRequestType.MORE_UPGRADE_OWNER;
//			break;
//		case R.id.tv_saveItem:
//			commandType = FinalConfigParams.ShortCutRequestType.MAP_SAVE_POI;
//			break;
//		default:
//			break;
//		}
//		return commandType;
//	}

//	public static Serializable getSwitchParam(Activity activity) {
//		MainTabActivity mainTabActivity = (MainTabActivity) (activity.getParent());
//		Bundle bundle = mainTabActivity.getSwitchParams();
//		Serializable paramValue = bundle.getSerializable("param");
//		return paramValue;
//	}
//
//	public static void clearSwitchParam(Activity activity) {
//		MainTabActivity mainTabActivity = (MainTabActivity) (activity.getParent());
//		if (mainTabActivity != null)
//			mainTabActivity.clearSwitchParams();
//	}

    public static boolean checkOwnerAndShowDialog(final Context context, final IMVPView imvpView) {
        String loginRole = ApplicationUtil.getInstance().getLoginRole();
        if (context == null) {
//            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SOMP_405);
            return false;
        } else if (CommonUtil.isNull(loginRole)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG015);
            return false;
        } else if (Constants.OWNER.equalsIgnoreCase(loginRole)) {
            return true;
        } else if (Constants.VISITOR.equalsIgnoreCase(loginRole)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JoinMeUtils.checkVisitor(imvpView);
                        }
                    }, true, R.string.upgrade_to_owner);
            return false;
        } else if ((Constants.DRIVER.equalsIgnoreCase(loginRole) || Constants.PROXY.equalsIgnoreCase(loginRole)) &&
                ApplicationUtil.getInstance().isAuthorized()) {
            return true;
        } else if ((Constants.DRIVER.equalsIgnoreCase(loginRole) || Constants.PROXY.equalsIgnoreCase(loginRole)) && !ApplicationUtil.getInstance().isAuthorized()) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG014);
            return false;
        }
        return false;
    }

    public static boolean checkOwnerAndShowDialog(final Context context) {
        String loginRole = ApplicationUtil.getInstance().getLoginRole();
        if (context == null) {
//            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SOMP_405);
            return false;
        } else if (CommonUtil.isNull(loginRole)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG015);
            return false;
        } else if (Constants.OWNER.equalsIgnoreCase(loginRole)) {
            return true;
        } else if (Constants.VISITOR.equalsIgnoreCase(loginRole)) {
            return false;
        } else if ((Constants.DRIVER.equalsIgnoreCase(loginRole) || Constants.PROXY.equalsIgnoreCase(loginRole)) &&
                ApplicationUtil.getInstance().isAuthorized()) {
            return true;
        } else if ((Constants.DRIVER.equalsIgnoreCase(loginRole) || Constants.PROXY.equalsIgnoreCase(loginRole)) && !ApplicationUtil.getInstance().isAuthorized()) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG014);
            return false;
        }
        return false;
    }

    //

    /**
     * @param @param  context
     * @param @return 设定文件
     * @return boolean 返回类型
     * @throws
     * @Title: checkVisitorShowDialog
     * @Description:
     */
    public static boolean checkVisitorShowDialog(final Activity context) {
        String loginRole = ApplicationUtil.getInstance().getLoginRole();
        if (context == null) {
//            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SOMP_405);
            return false;
        } else if (CommonUtil.isNull(loginRole)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG015);
            return false;
        } else if (Constants.OWNER.equalsIgnoreCase(loginRole)) {
            return true;
        } else if (Constants.VISITOR.equalsIgnoreCase(loginRole)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JoinMeUtil joinMeUtil = new JoinMeUtil(context, false);
                            joinMeUtil.checkVisitor(false);
                        }
                    }, true, R.string.upgrade_to_owner);
            return false;
        } else if (Constants.DRIVER.equalsIgnoreCase(loginRole) || Constants.PROXY.equalsIgnoreCase(loginRole)) {
            return true;
        }
        return false;
    }

    public static boolean checkDataRefreshAuth(Activity context, String service) {
        if (checkVisitorShowDialog(context)) {
//			if(!BusinessUtil.checkPackageRight(service, context,true)) {
//				return false;
//			}
            if (!isServiceEntitlement(context, service)) {
                AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                        context.getString(R.string.SB002_MSG001));
                return false;
            }
            return true;
        }
        return false;
    }

    public static boolean checkDriverOrProxyAndShowDialog(final Activity context) {
        String loginRole = ApplicationUtil.getInstance().getLoginRole();
        if (context == null) {
//            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SOMP_405);
            return false;
        } else if (CommonUtil.isNull(loginRole)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG015);
            return false;
        } else if (Constants.OWNER.equalsIgnoreCase(loginRole)) {//车主
            return true;
        } else if (Constants.VISITOR.equalsIgnoreCase(loginRole)) {//潜客
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JoinMeUtil joinMeUtil = new JoinMeUtil(context, false);
                            joinMeUtil.checkVisitor(false);
                        }
                    }, true, R.string.upgrade_to_owner);
            return false;
        } else if (Constants.DRIVER.equalsIgnoreCase(loginRole) || Constants.PROXY.equalsIgnoreCase(loginRole)) {
            return true;
        }
        return false;
    }

    public static boolean isServiceEntitlement(Context context, String service) {
        boolean isServiceEntitlement = false;
        List<ServiceEntitlement> serviceEntitlements = ApplicationUtil.getInstance().getServiceEntitlement();
        if (serviceEntitlements != null && serviceEntitlements.size() > 0) {
            for (ServiceEntitlement serviceEntitlement : serviceEntitlements) {
                if (service.equals(serviceEntitlement.getObjectID())) {
                    if ("true".equals(serviceEntitlement.getEntitledIndicator())) {
                        isServiceEntitlement = true;
                    }
                }
            }
        }
        return isServiceEntitlement;
    }

    /**
     * @Title: checkRemoteControl @Description: 用于遥控页面触发button的条件 @param @param
     * context @param @param service @param @param iCommandType
     * eg:R.id.lockdoor_id,按钮ID @param @return 设定文件 @return boolean 返回类型 @throws
     */
    public static boolean checkRemoteControl(final Context context, String service, int iCommandType, IMVPView imvpView) {
        if (!checkOwnerAndShowDialog(context, imvpView)) {
            return false;
        }
        if (!ApplicationUtil.getInstance().isBBWC()) {
            AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                    context.getString(R.string.vehicle_bbwc_error));
            return false;
        }
        if (!ApplicationUtil.getInstance().isRemoteControlOpt()) {
            AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                    context.getString(R.string.opt_out_alert));
            return false;
        }
        return checkPackageRight(service, context, true);
    }

    public static boolean checkRemoteControl(final Context context, String service) {
        if (!checkOwnerAndShowDialog(context)) {
            return false;
        }
        if (!ApplicationUtil.getInstance().isBBWC()) {
            AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                    context.getString(R.string.vehicle_bbwc_error));
            return false;
        }
        if (!ApplicationUtil.getInstance().isRemoteControlOpt()) {
            AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                    context.getString(R.string.opt_out_alert));
            return false;
        }
        return checkPackageRight(service, context, true);
    }

    public static void showOverDueBuyPackageDialog(final Context context) {
        AlertDialogUtil.showConfigureDialog(context, context.getString(R.string.dialog_warning),
                context.getString(R.string.over_due_user_buy),
                context.getString(R.string.over_due_user_btn), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(context, OnstarBuyPackageActivity.class);
                        Bundle b = new Bundle();
                        b.putSerializable("packageType", PackageType.CORE);
                        i.putExtras(b);
                        context.startActivity(i);
                    }
                });
    }

    public static String getCheckPackageRightString(String service, final Context context) {
        String result = "";
        if (Constants.entitlementRights.contains(service)) {
            if (ApplicationUtil.getInstance().isExpiredSubscriber()) {
                if (DeviceUtil.isChineseLanguage()) {
                    result = context.getString(R.string.over_due_user_buy);
                } else {
                    result = context.getString(R.string.over_due_user);
                }

            } else if (!isServiceEntitlement(context, service)) {
                result = context.getString(R.string.SB002_MSG001);
            }
        } else {//如果购买套餐都是针对车辆服务，则不会走如下:
            if (!isServiceEntitlement(context, service)) {
                result = context.getString(R.string.SB002_MSG001);
            }
        }
        return result;
    }

    //
    public static boolean checkPackageRight(String service, final Context context, boolean isShowDialog) {
        boolean result = false;
        if (Constants.entitlementRights.contains(service)) {
            if (ApplicationUtil.getInstance().isExpiredSubscriber()) {
                result = false;
                if (isShowDialog) {
                    if (DeviceUtil.isChineseLanguage()) {
                        showOverDueBuyPackageDialog(context);
                    } else {
                        showOverdueUserDialog(context);
                    }

                }
            } else if (!isServiceEntitlement(context, service)) {
                result = false;
                if (isShowDialog) {
                    AlertDialogUtil.showConfigureDialog(context, context.getString(R.string.dialog_warning),
                            context.getString(R.string.SB002_MSG001),
                            context.getString(R.string.call_out), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent();
                                    intent.setAction(Intent.ACTION_CALL);
                                    intent.setData(Uri.parse("tel:" + context.getString(R.string.pin_phone) + context.getString(R.string.extension_number)));
                                    context.startActivity(intent);
                                }
                            });
                }
            } else {
                result = true;
            }
        } else {//如果购买套餐都是针对车辆服务，则不会走如下:
            if (!isServiceEntitlement(context, service)) {
                result = false;
                if (isShowDialog) {
                    AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning),
                            context.getString(R.string.SB002_MSG001));
                }
            } else {
                result = true;
            }
        }
        return result;
    }

    //
//    /**
//     * @Title: checkVechileLocation @Description:用于在map页面查找车辆位置button条件判断，部分。 @param @param
//     * activity @param @return 设定文件 @return boolean 返回类型 @throws
//     */
//    public static boolean checkVechileLocation(Activity activity) {
//        if (!CommonUtil.checkNetWorkState(activity)) {
//            AlertDialogUtil.showAlertDialog(activity, activity.getString(R.string.dialog_warning),
//                    activity.getString(R.string.SOMP_901));
//            return false;
//        }
////		if (!ApplicationUtil.getInstance().isLogin()) {
////			MainTabActivity mainTabActivity = (MainTabActivity) activity.getParent();
////			mainTabActivity.switchToTab(R.id.button_tab_bar_poi, R.id.vehicleLocation_button_id);
////			return false;
////		}
//        if (ApplicationUtil.getInstance().isAutoLogings()) {
//            AlertDialogUtil.showAlertDialog(activity, activity.getString(R.string.dialog_warning),
//                    activity.getString(R.string.loading));
//            return false;
//        }
//        if (!isServiceEntitlement(activity, Constants.ENTITLEMENT_M06FIND_CAR)) {
//            return false;
//        }
////		if (!ApplicationUtil.isFmvOptinStatus(activity)) {
////			AlertDialogUtil.showAlertDialog(activity, activity.getString(R.string.dialog_warning),
////					activity.getString(R.string.opt_out_alert));
////			activity.setRouteSearchStatus(RouteSearchStatusType.Completed);
////			return false;
////		}
////		if (checkInProgressCommand(activity, null)) {// 传空代表遥控页的操作
////			activity.setRouteSearchStatus(RouteSearchStatusType.Completed);
////			return false;
////		}
////		if (checkInProgressCommand(activity, RemoteCommandsType.COMMANDS_LOCATION)) {// 检查是否正在查询车辆位置
////			activity.setRouteSearchStatus(RouteSearchStatusType.Completed);
////			return false;
////		}
//        return true;
//    }
//
//    public static boolean checkTBTODD(Activity activity, RemoteCommandsType commandsType) {
//        MainTabActivity tabActivity = (MainTabActivity) (activity.getParent());
//        if (!ApplicationUtil.getInstance().isLogin()) {
////			MainTabActivity mainTabActivity = (MainTabActivity) activity.getParent();
////			if (commandsType == RemoteCommandsType.COMMANDS_TBT_ROUTE) {
////				mainTabActivity.switchToTab(R.id.button_tab_bar_poi, R.id.sendInfoToCarBtn);
////			} else {
////				mainTabActivity.switchToTab(R.id.button_tab_bar_poi, R.id.sendToODDBtn);
////			}
////			return false;
//        }
//        if (ApplicationUtil.getInstance().isAutoLogings()) {
//            AlertDialogUtil.showAlertDialog(activity, activity.getString(R.string.dialog_warning),
//                    activity.getString(R.string.loading));
//            return false;
//        }
//        if (!checkDriverOrProxyAndShowDialog(tabActivity)) {
//            return false;
//        }
//        if (!isServiceEntitlement(activity, Constants.ENTITLEMENT_M05NAVIGATION)) {
//            AlertDialogUtil.showAlertDialog(activity, activity.getString(R.string.dialog_warning),
//                    activity.getString(R.string.SB002_MSG001));
//            return false;
//        }
//        if (checkInProgressCommand(activity, null)) {// 传空代表遥控页的操作
//            PoiLocationInfoInstance.getInstance().setRouteSearchStatus(RouteSearchStatusType.Completed);
//            return false;
//        }
//        return true;
//    }
//
    public static boolean checkTokenExpired(Context context) {
        String tokenTime = PreferencesUtls.getInstance(context).getString(Constants.TIME_LOCAL_TOKEN, "");
        LogManager.getInstance().d("token time" + tokenTime);
        long periodTime = 0;
        if (!CommonUtil.isNull(tokenTime)) {
            periodTime = System.currentTimeMillis() - Long.valueOf(tokenTime);
            if (periodTime <= Constants.TIME_EXPIRE_TOKEN) {
                return false;
            }
        }
        LogManager.getInstance().d("periodTime is " + periodTime + ": token expired");
        return true;
    }

    public static boolean checkPinPageTokenExpired(Context context) {
        String tokenTime = PreferencesUtls.getInstance(context).getString(Constants.TIME_LOCAL_TOKEN, "");
        String token = PreferencesUtls.getInstance(context).getString(Constants.ACCESS_TOKEN, "");
        LogManager.getInstance().d("token time" + tokenTime);
        long periodTime = 0;
        if (!CommonUtil.isNull(tokenTime) && !CommonUtil.isNull(token)) {
            periodTime = System.currentTimeMillis() - Long.valueOf(tokenTime);
            String[] tokenSplit = token.split("@");
            boolean isNormal = true;
            if (tokenSplit.length > 0 && Constants.ACCESS_TOKEN_HIGH.equals(tokenSplit[0])) {
                isNormal = false;
            }
            if (periodTime <= Constants.TIME_EXPIRE_TOKEN && !isNormal) {
                LogManager.getInstance().d("periodTime is " + periodTime + ": token not expired");
                return false;
            }
        }
        LogManager.getInstance().d("periodTime is " + periodTime + ": token expired");
        return true;
    }

    public static boolean checkIDTokenExpired(Context context) {
        String tokenTime = PreferencesUtls.getInstance(context).getString(Constants.TIME_ID_TOKEN, "");
        LogManager.getInstance().d("token time" + tokenTime);
        long periodTime = 0;
        if (!CommonUtil.isNull(tokenTime)) {
            periodTime = System.currentTimeMillis() - Long.valueOf(tokenTime);
            if (periodTime <= Constants.TIME_EXPIRE_ID_TOKEN) {
                return false;
            }
        }
        LogManager.getInstance().d("periodTime is " + periodTime + ": token expired");
        return true;
        // return false;//不超时
    }
//
//    /**
//     * @Title: noPinCheckTokenExpired @Description:
//     * 针对不要输入pin码的车辆操作，对其进行token过期检验 @param @param context 设定文件 @return
//     * void 返回类型 @throws
//     */
//    public void noPinCheckTokenExpired(final Context context) {
//        AuthorizeUtil authUtils = new AuthorizeUtil(context);
//        authUtils.setResultListener(new AuthorResultListener() {
//            @Override
//            public void onSuccess(AuthorizeType type) {
//                switch (type) {
//                    case PINREAUTHORIZE:
//                        break;
//                    default:
//                        break;
//                }
//            }
//
//            @Override
//            public void onFail(AuthorizeType type, final HttpException e) {
//                switch (type) {
//                    case PINREAUTHORIZE:
//                        AlertDialogUtil.showDialogByExceptionCode(context, e);
//                        break;
//                    default:
//                        break;
//                }
//            }
//        });
//        if (BusinessUtil.checkTokenExpired(context)) {
//            AuthTokenRequestEntity entity = BusinessUtil.createAuthTokenRequestEntity();
//            authUtils.pinReauthenticationForNoPin(entity);
//        }
//    }
//

    /**
     * @Title: createAuthTokenRequestEntity @Description: load data for get
     * token @param @return 设定文件 @return AuthTokenRequestEntity 返回类型 @throws
     */
    public static AuthTokenRequestEntity createAuthTokenRequestEntity() {
        AuthTokenRequestEntity entity = new AuthTokenRequestEntity();
        entity.setClientId("ONSTAR_CHINA_MOBILE_AND_I");
        entity.setClientSecret("oNQYdymp6CdQM3fLHVuY");
        entity.setScope("msso onstar mag_subscriber mag_visitor");
        return entity;
    }


    public static void clearOnstarAppContext(Context context) {
        OnstarApplication application = (OnstarApplication) (context.getApplicationContext());
        ApplicationUtil.getInstance().clearData();
//        application.setLogin(false);
//        application.setLoginRole(null);
//        application.setAccountId("");
        application.setBrocastCount("");
//        application.setCurrentAccount(null);
//        application.setCurrentVehicle(null);
//        application.setFmvOptinStatus(false);
//        application.setIdpID("");
//        application.setPin(false);
//        application.setRemoteControlOptinStatus(false);
//        application.setServiceEntitlement(null);
//        application.setSubscriberID("");
//        application.setVehicleUnitFeatures(null);
//        application.setSupportedDiagnostic(null);
//        application.setVolt(false);
//        application.setBuick(false);
        application.setHeadImgRes(null);
//        ApplicationUtil.getInstance().setServiceItems(null);
//        application.setCarAssessStatusItem(null);
//        application.setItem(null);
//        application.setToken("");
//        application.setD2jbi(false);
//        application.setMobile("");
//        application.setEmail("");
        //此时取消车检提醒闹钟
        new AlarmProxy(context).cancel(AlarmActionType.VEHICLE_INSPECTION_ACTION);
//        application.setSharedPoiItemInfo(null);
    }

    public static void saveSessionAfterLogin(Context context, Subscriber subscriber) {
        String deviceId = new DeviceUtil(context).getDeviceID();
        SessionEntity sessionEntity = new SessionEntity();
        sessionEntity.setEmail(subscriber.getEmail());
        sessionEntity.setMobileNumber(subscriber.getPhoneNumber());
        sessionEntity.setUserID(subscriber.getIdpID());
        sessionEntity.setUserName(subscriber.getIdpID());
        sessionEntity.setSubscriberID(subscriber.getSubscriberID());
        sessionEntity.setDeviceToken(deviceId);
        sessionEntity.setRole(ApplicationUtil.getInstance().getLoginRole());
        sessionEntity.setAccountID(ApplicationUtil.getInstance().getAccountId());
        if (!CommonUtil.isNull(ApplicationUtil.getInstance().getCurrentVehicle())) {
            List<Vehicle> vehicles = new ArrayList<>();
            Vehicle currentVehicle = ApplicationUtil.getInstance().getCurrentVehicle();
//            if (currentVehicle != null) {
//                currentVehicle.setYear(currentVehicle.getModelYear());
//            }
            vehicles.add(currentVehicle);
            sessionEntity.setVehicles(vehicles);
        }
        NotificationControl.getInstants(context).saveSessionAfterLogin(sessionEntity);
    }

    //
//
//    private static List<Activity> list = new ArrayList<Activity>();
//
//    public static void addActivity(Activity activity) {
//        list.add(activity);
//    }
//
//    public static void removeAllActivity() {
//        if (list != null && list.size() > 0) {
//            for (Activity activity : list) {
//                activity.finish();
//            }
//        }
//    }
//
//
//    /**
//     * @param @param commandsType    设定文件
//     * @return void    返回类型
//     * @throws
//     * @Title: initPollingStatusBeforePolling
//     * @Description: 记录用户是否已经点击车辆操作，若已点击则不让再点.
//     */
    public static void initPollingStatusBeforePolling(RemoteCommandsType commandsType, String vin, VehicleManager manager) {
        PollingEntity entity = new PollingEntity();
        entity.setVin(vin);
        entity.setRequestType(commandsType.value());
        manager.initPollingStatusBeforePolling(entity);
    }

    //
    public static void updateToFailPollingStatusBeforePolling(RemoteCommandsType commandsType, String vin, VehicleManager manager) {
        PollingEntity entity = new PollingEntity();
        entity.setVin(vin);
        entity.setRequestType(commandsType.value());
        manager.updateToFailPollingStatusBeforePolling(entity);
    }

    //
//    public static boolean checkAutoLogin(Context context, OnClickListener listener) {
//        if (ApplicationUtil.getInstance().isAutoLogings()) {
//            AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning), context.getString(R.string.home_login_ing), listener);
//            return true;
//        }
//        return false;
//    }
//
//    public static boolean checkAutoLogin(Context context) {
//        if (ApplicationUtil.getInstance().isAutoLogings()) {
//            AlertDialogUtil.showAlertDialog(context, context.getString(R.string.dialog_warning), context.getString(R.string.home_login_ing), new OnClickListener() {
//                @Override
//                public void onClick(DialogInterface dialog, int which) {
//
//                }
//            });
//            return true;
//        }
//        return false;
//    }
//
    public static boolean isAutoSendPin(RemoteCommandsType commandType, Context context) {
        return !PinUtil.isNeedPin(context) && !(commandType == RemoteCommandsType.COMMANDS_ALERT);
    }

    //
//    public static boolean isApplicationBroughtToBackground(final Context context) {
//        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
//        if (!tasks.isEmpty()) {
//            ComponentName topActivity = tasks.get(0).topActivity;
//            if (!topActivity.getPackageName().equals(context.getPackageName())) {
//                return true;
//            }
//        }
//        return false;
//
//    }
//
//    public static String getCurrentActivity(final Context context) {
//        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
//        if (!tasks.isEmpty()) {
//            ComponentName topActivity = tasks.get(0).topActivity;
//            if (topActivity.getPackageName().equals(context.getPackageName())) {
//                return topActivity.getClassName();
//            }
//        }
//        return "";
//    }
//
//    /**
//     * 截取offerid的首两个字母EB判断是否是早鸟
//     *
//     * @param groupList
//     * @return
//     */
//    public static boolean isEBPackage(List<PackageInfo> groupList) {
//        final String EB_MODE = "EB";
//        if (groupList != null && groupList.size() > 0) {
//            for (PackageInfo packageInfo : groupList) {
//                String offerId = packageInfo.getPackageOfferId();
//                if (!CommonUtil.isNull(offerId) && offerId.length() > 2) {
//                    if (EB_MODE.equalsIgnoreCase(offerId.substring(0, 2))) {
//                        return true;
//                    }
//                    continue;
//                }
//            }
//        }
//        return false;
//    }
//
//    /**
//     * 截取offerid的首两个字母EB判断是否是早鸟
//     *
//     * @param groupList
//     * @return
//     */
//    public static boolean isEBPackageRule2(List<PackageInfo> groupList) {
//        final String isEBPackage = "1";
//        String ebPackage = null;
//        if (groupList != null && groupList.size() > 0) {
//            for (PackageInfo packageInfo : groupList) {
//                ebPackage = packageInfo.getIsEBPackage();
//                if (!CommonUtil.isNull(ebPackage)) {
//                    if (isEBPackage.equals(ebPackage)) {
//                        return true;
//                    }
//                    continue;
//                }
//            }
//        }
//        return false;
//    }
    public static boolean isMroShow(Activity activity) {
        return DeviceUtil.isChineseLanguage() && ApplicationUtil.getInstance().isLogin() && Constants.OWNER.equalsIgnoreCase(ApplicationUtil.getInstance().getLoginRole());
    }

    public static String getResponse(SparseArray<String> reseponseData, Context context) throws OnStarException {
        if (context == null) {
            return null;
        }
        if (reseponseData != null && reseponseData.size() != 0) {
            int responseCode = -1;
//            for (Integer key : reseponseData.keySet()) {
//                responseCode = key;
//                break;
//            }
            for (int i = 0; i < reseponseData.size(); i++) {
                responseCode = reseponseData.keyAt(i);
                break;
            }
            if (responseCode != 200 && responseCode != 202) {
                CommonError commonError = GsonHelper.fromJson(reseponseData.get(responseCode), CommonError.class);
                HttpException httpException = new HttpException(commonError.getErrorCode(), commonError.getErrorMessage());
                ErrorInfo errorInfo = ErrorCodeUtil.getErrorInfoByHttpException(context, httpException);
                throw new HttpException(errorInfo.getCode(), errorInfo.getMsg());
            } else {
                return reseponseData.get(responseCode);
            }
        }
        return null;
    }

    private static boolean isVisitor(final IMVPView imvpView, Bundle bundle) {
        if (ApplicationUtil.getInstance().isLogin() && ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR) && !isVisitorJump(bundle, imvpView)) {
            AlertDialogUtil.showAlertDialog(imvpView.onActivity(), R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JoinMeUtils.checkVisitor(imvpView);
                        }
                    }, true, R.string.upgrade_to_owner);
            return true;
        }
        return false;
    }

    public static void jumpActivity(Bundle bundle, IMVPView imvpView, Class<?> jumpClazz) {
        if (bundle != null) {
            if (isVisitor(imvpView, bundle)) {
                return;
            }
            try {
                BaseFragmentActivity activity = (BaseFragmentActivity) imvpView.onActivity();
                Class<?> clazz = Class.forName(jumpClazz.getName());
                if (clazz.newInstance() instanceof Fragment) {
                    Fragment fragment = (Fragment) clazz.newInstance();
                    if (!CommonUtil.isNull(bundle)) {
                        fragment.setArguments(bundle);
                    }
                    activity.changeFragment(fragment, clazz, false);
                } else {
                    Intent intent = new Intent(activity, clazz);
                    if (!CommonUtil.isNull(bundle)) {
                        intent.putExtras(bundle);
                    }
                    activity.startActivity(intent);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private static boolean isVisitorJump(Bundle bundle, IMVPView imvpView) {
        if (bundle == null) return false;
        String itemTitle = bundle.getString("title");
        if (TextUtils.isEmpty(itemTitle) || imvpView == null)
            return false;
        BaseFragmentActivity activity = (BaseFragmentActivity) imvpView.onActivity();
        String search = activity.getString(R.string.function_poi_search);
        String traffic = activity.getString(R.string.function_poi_traffic);
        String more = activity.getString(R.string.nav_more_search);
        return itemTitle.equalsIgnoreCase(search) || itemTitle.equalsIgnoreCase(traffic) || itemTitle.equalsIgnoreCase(more);
    }

    public static boolean isVisitor(final Context context, final IMVPView view) {
        if (ApplicationUtil.getInstance().isLogin() && ApplicationUtil.getInstance().getLoginRole().equalsIgnoreCase(JoinMeConstants.VISITOR)) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ProgressDialog progress_dialog = new ProgressDialog(context);
                            progress_dialog.setMessage(context.getString(R.string.sendingRequest_wait));
                            JoinMeUtils.checkVisitor(view);
                        }
                    }, true, R.string.upgrade_to_owner);
            return true;
        }
        return false;
    }

    public static void showCommandFailToast(String msg, Context context, final Action1 action) {
        new ToastView(context).toast(msg, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Observable.create(new Observable.OnSubscribe<Object>() {
                    @Override
                    public void call(rx.Subscriber<? super Object> subscriber) {
                        subscriber.onNext(new Object());
                    }
                }).subscribe(action);
            }
        });
    }

    public static boolean isVisitor(final Context context) {
        if (ApplicationUtil.getInstance().isLogin() && JoinMeConstants.VISITOR.equalsIgnoreCase(ApplicationUtil.getInstance().getLoginRole())) {
            AlertDialogUtil.showAlertDialog(context, R.string.dialog_warning, R.string.SB021_MSG013,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            JoinMeUtil joinMeUtil = new JoinMeUtil(context, false);
                            joinMeUtil.checkVisitor(false);
                        }
                    }, true, R.string.upgrade_to_owner);
            return true;
        }
        return false;
    }


}
